package com.dzl.movie;

import com.alibaba.fastjson.JSONObject;
import com.dzl.base.controller.BaseController;
import com.dzl.moive.pojo.WelfareMovieOrder;
import com.dzl.moive.pojo.dto.WelfareMovieOrderRefundDto;
import com.dzl.moive.pojo.dto.WelfareMovieOrderSignDesDto;
import com.dzl.moive.pojo.query.WelfareMovieOrderListQuery;
import com.dzl.moive.pojo.vo.WelfareMovieOrderInfoVo;
import com.dzl.moive.pojo.vo.WelfareMovieOrderListVo;
import com.dzl.moive.service.WelfareMovieOrderService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import com.dzl.util.PageUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电影订单信息表(WelfareMovieOrder)表控制层
 * @author ChenLong
 * @date 2021-11-06 14:45:11
 */
@RestController
@RequestMapping("/welfareMovieOrder")
public class WelfareMovieOrderController extends BaseController {

    @Autowired
    private WelfareMovieOrderService service;

    /**
     * 顶部订单数量
     * @date 2021/11/5 10:37
     * @author ChenLong
     * @param query 查询条件
     * @return com.dzl.util.JsonResult<java.util.List<java.lang.Integer>>
     */
    @GetMapping("/getMovieOrderCount")
    public JsonResult<List<Integer>> getMovieOrderCount(WelfareMovieOrderListQuery query) {
        query.setEnterpriseId(getAdminInfo().getEnterpriseId());
        return JsonResult.success(service.getMovieOrderCount(query));
    }

    /**
     * 分页查询电影订单
     * @date 2021/11/4 15:10
     * @author ChenLong
     * @param query 查询条件
     * @return com.dzl.util.PageUtils<com.dzl.moive.pojo.vo.WelfareMovieOrderFlowVo>
     */
    @GetMapping("/getMovieOrderVoPage")
    public PageUtils<WelfareMovieOrderListVo> getMovieOrderVoPage(WelfareMovieOrderListQuery query) {
        query.setEnterpriseId(getAdminInfo().getEnterpriseId());
        PageInfo<WelfareMovieOrderListVo> pageInfo = service.getMovieOrderVoPage(query);
        return new PageUtils<>(pageInfo);
    }

    /**
     * 查询电影订单详情
     * @date 2021/11/4 15:10
     * @author ChenLong
     * @param orderId 订单ID
     * @return com.dzl.util.PageUtils<com.dzl.moive.pojo.vo.WelfareMovieOrderFlowVo>
     */
    @GetMapping("/getMovieOrderById")
    public JsonResult<WelfareMovieOrderInfoVo> getMovieOrderById(Integer orderId) {
        return JsonResult.success(service.getMovieOrderById(orderId));
    }

    /**
     * 订单退款
     * @param dto 退款订单信息
     * @return com.dzl.util.JsonResult
     * @date 2021/5/31 16:41
     * @author caobucao
     */
    @PostMapping("updateRefundOrderForMovie")
    public JsonResult<Integer> updateRefundOrderForMovie(@RequestBody WelfareMovieOrderRefundDto dto) {
        if (EmptyUtils.isEmpty(dto.getOrderId())){
            JsonResult.paramErrWithMsg("参数错误");
        }
        dto.setUpdater(getAdminInfo().getId());
        dto.setUpdaterName(getAdminInfo().getUserName());
        return JsonResult.success(service.updateRefundOrderForMovie(dto));
    }

    /**
     * 订单退款
     * @param dto 退款订单信息
     * @return com.dzl.util.JsonResult
     * @date 2021/5/31 16:41
     * @author caobucao
     */
    @PostMapping("updateMovieOrderSignDes")
    public JsonResult<Integer> updateMovieOrderSignDes(@RequestBody WelfareMovieOrderSignDesDto dto) {
        if (EmptyUtils.isEmpty(dto.getOrderId())){
            JsonResult.paramErrWithMsg("参数错误");
        }
        WelfareMovieOrder welfareMovieOrderOpt = new WelfareMovieOrder();
        welfareMovieOrderOpt.setId(dto.getOrderId());
        welfareMovieOrderOpt.setSignDes(dto.getSignDes());
        service.updateByPrimaryKeySelective(welfareMovieOrderOpt);
        return JsonResult.success();
    }

}
